﻿using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@TestRunner.Imports


namespace @Test.Namespace
{
	
	public partial class @Test.ClassName
	{


@{
	foreach (var constructor in Class.Constructors.Where(c => c.IsCreatable)) 
	{ 
		<text>
		
            @Tag("IEditableObject")
    	    @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginCancel_Simple")()
		    {
                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = @constructor.GetConstructorCode();
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }

                ((IEditableObject)objectUnderTest).BeginEdit();
                ((IEditableObject)objectUnderTest).CancelEdit();
		    }

            @Tag("IEditableObject")
            @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginEnd_Simple")()
		    {
                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = @constructor.GetConstructorCode();
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }

                ((IEditableObject)objectUnderTest).BeginEdit();
                ((IEditableObject)objectUnderTest).EndEdit();
		    }

						


            @Tag("IEditableObject")
    	    @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginCancel")()
		    {
                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = GetObject(1);
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }

			    var expected = GetValues(objectUnderTest); //CancelEdit should return us to these values

			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 2);
                ((IEditableObject)objectUnderTest).CancelEdit();

			    var diffs = GetDiffs(expected, objectUnderTest);
			    @Assert.AreEqual("0", "diffs.Count");

		    }

            @Tag("IEditableObject")
            @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginEnd")()
		    {
                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = GetObject(1);
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }

           
			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 2);
			    var expected = GetValues(objectUnderTest); //EndEdit shouldn't change any values
                ((IEditableObject)objectUnderTest).EndEdit();

			    var diffs = GetDiffs(expected, objectUnderTest);
			    @Assert.AreEqual("0", "diffs.Count");
		    }



            @Tag("IEditableObject")
    	    @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginBeginCancelCancel")()
		    {
                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = GetObject(1);
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }

			    var expected = GetValues(objectUnderTest); //The second CancelEdit should return us to these values

			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 2);

			    ((IEditableObject)objectUnderTest).BeginEdit(); //This is a no-op
			    SetValues(objectUnderTest, 3);

			    ((IEditableObject)objectUnderTest).CancelEdit(); //and we are back to the original values

			    var diffs1 = GetDiffs(expected, objectUnderTest);
			    @Assert.AreEqual("0", "diffs1.Count");

			    ((IEditableObject)objectUnderTest).CancelEdit(); //this is a no-op

			    var diffs2 = GetDiffs(expected, objectUnderTest); 
			    @Assert.AreEqual("0", "diffs2.Count");


		    }

            @Tag("IEditableObject")
    	    @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginBeginCancelEnd")()
		    {

                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = GetObject(1);
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }

			    var expected = GetValues(objectUnderTest); //The first CancelEdit should return us to these values

			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 2);


			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 3);

			    ((IEditableObject)objectUnderTest).CancelEdit();

			    var diffs1 = GetDiffs(expected, objectUnderTest);
			    @Assert.AreEqual("0", "diffs1.Count");

			    ((IEditableObject)objectUnderTest).EndEdit(); //this is a no-op

			    var diffs2 = GetDiffs(expected, objectUnderTest); 
			    @Assert.AreEqual("0", "diffs2.Count");


		    }


            @Tag("IEditableObject")
    	    @TestAttribute
            public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginBeginEndEnd")()
		    {

                @Class.FullName objectUnderTest;

			    try
			    {
				    objectUnderTest = GetObject(1);
			    }
			    catch (ArgumentException)
			    {
				    //OK
                    return;
			    }


			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 2);

			    ((IEditableObject)objectUnderTest).BeginEdit();
			    SetValues(objectUnderTest, 3);

			    var expected = GetValues(objectUnderTest);

			    ((IEditableObject)objectUnderTest).EndEdit();

			    var diffs1 = GetDiffs(expected, objectUnderTest);
			    @Assert.AreEqual("0", "diffs1.Count");

			    ((IEditableObject)objectUnderTest).EndEdit();

			    var diffs2 = GetDiffs(expected, objectUnderTest); 
			    @Assert.AreEqual("0", "diffs2.Count");

		    }

        </text>	
	}	
}
	}
}

